<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        // es5造类
        /* function Person(name,age) {
            this.name = name;
            this.age = age;
        }
        Person.prototype.sayName = function() {
            return this.name;
        }
        let p1 = new Person('小马哥',28);
        console.log(p1);
         */
        class Person {
            // 实例化的时候会立即被调用
            constructor(name, age) {
                this.name = name;
                this.age = age;
            }

        }
        // 通过Object.assign()方法一次性向类中添加多个方法
        Object.assign(Person.prototype, {
            sayName() {
                return this.name
            },
            sayAge() {
                return this.age
            }
        })
        let p1 = new Person('小马哥', 28);
        console.log(p1);
    </script>

</body>

</html>